package com.liang.thread;

import com.liang.algorithm.Pearson;
import com.liang.pojo.User;
import com.liang.pojo.UserAction;
import com.liang.service.UserService;
import com.liang.service.impl.UserActionServiceImpl;
import com.liang.service.impl.UserCoordinationServiceImpl2;
import com.liang.service.impl.UserServiceImpl;

import java.util.List;

//协同表2更新线程
public class ThreadC implements Runnable{
    private int id;
    private static boolean flag=true;

    public void setId(int id) {
        this.id = id;
    }

    public void run() {
        UserActionServiceImpl userActionService = new UserActionServiceImpl();
        UserCoordinationServiceImpl2 impl2 = new UserCoordinationServiceImpl2();
        List<UserAction> x = userActionService.getUserActionListById(id);
        int[] idList = userActionService.getUserId();
        Pearson pearson = new Pearson();//皮尔森公式
        for (int i : idList) {
            if (i!=id){
                double y = pearson.getPearsonCorrelationScore(x, userActionService.getUserActionListById(i));
                if(y<0){
                    y=1-(1+y);
                }
                impl2.insertUserCoordinationMapper(id,i,y);
            }
        }
        flag=false;
    }
    public boolean getFlag(){
        return flag;
    }
}
